<template>
  <div class="xpsf">
    <div class="xpsf-text">
      <span class="left-text">新品首发</span>
      <span class="right-text" @click="gotomorexpsf()">更多新品首发></span>
    </div>

    <div class="goods-grid">
      <div class="goods-item" v-for="goods in newGoodsList" :key="goods.id" @click="goToGoodsDetail(goods.id)">
        <img :src="goods.picUrl" class="goods-image" :alt="goods.name" />
        <div class="goods-info">
          <div class="goods-name-price">
            <span class="goods-name">{{ goods.name }}</span>
            <span class="retail-price">¥{{ goods.retailPrice }}</span>
          </div>
          <div class="counter-price">¥{{ goods.counterPrice }}</div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import { getHomeData } from '@/api/home'
import { useRouter } from 'vue-router'
const router = useRouter()
const newGoodsList = ref([])
onMounted(async () => {
  const response = await getHomeData()
  newGoodsList.value = response.data.newGoodsList
})
const goToGoodsDetail = (id) => {
  router.push({
    path: '/goods/detail',
    query: { id }
  })
}
const gotomorexpsf = () => {
  router.push({
    path: '/goods/morexpsf',
  })
}
</script>

<style scoped>
.xpsf-text {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 15px 12px;
  background: white;
}

.left-text {
  font-size: 16px;
  font-weight: bold;
  color: #333;
}

.right-text {
  font-size: 12px;
  color: #999;
}

.goods-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  padding: 0 10px 10px;
  background: white;
}

.goods-item {
  display: flex;
  flex-direction: column;
  border-radius: 8px;
  overflow: hidden;
  background: white;
}

.goods-image {
  width: 100%;
  height: 160px;
  object-fit: contain;
  background: white;
}

.goods-info {
  padding: 10px;
}

.goods-name-price {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
}

.goods-name {
  font-size: 13px;
  color: #333;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding-right: 8px;
}

.retail-price {
  font-size: 14px;
  color: #ff2f55;
  font-weight: bold;
  flex-shrink: 0;
}

.counter-price {
  font-size: 11px;
  color: #999;
  text-decoration: line-through;
  text-align: right;
}
</style>